package mark.tom.friend.provider.impl;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import mark.tom.friend.app.CustomDBHelper;
import mark.tom.friend.bean.db.DaoMaster;
import mark.tom.friend.consts.DBKeyConsts;
import mark.tom.friend.consts.ProviderRouterConsts;

public class AppConfigProviderImpl extends ContentProvider {

    private static final int MATCH_ONE_CODE = 1;
    private static UriMatcher uriMatcher;
    private SQLiteDatabase db;

    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(ProviderRouterConsts.CONTENT_AUTHORITY, ProviderRouterConsts.CONTENT_PATH, MATCH_ONE_CODE);
    }

    @Override
    public boolean onCreate() {
        DaoMaster.OpenHelper helper = new CustomDBHelper(getContext(), DBKeyConsts.DB_KEY_NAME);
        db = helper.getReadableDatabase();
        return false;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
        Cursor cursor = null;
        switch (uriMatcher.match(uri)) {
            case MATCH_ONE_CODE : {
                cursor = db.query("APP_CONFIG_DO", new String[] {"DEBUG_ABLE", "SERVER_CONFIG", "EXTRA_CONFIG"},
                        "PACKAGE_NAME=?", selectionArgs, null, null, null);
                break;
            }
            default: {
                break;
            }
        }
        return cursor;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
        return null;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
        return 0;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
        return 0;
    }
}
